<template>
    <div>
        <div class="header-abs" v-show="headerShow">
            <router-link tag="div" to="/" class="iconfont header-abs-back">&#xe624;</router-link>
        </div>
        <div class="header-fixed" :style="opacityStyle" v-show="!headerShow">
            <router-link to="/">
                <div class="header-left">
                    <div class="iconfont back-icon">&#xe624;</div>
                </div>
            </router-link>
            <h1 class="header-tit">{{ sightName }}</h1>
        </div>
    </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  props: {
    sightName: String
  },
  data() {
    return {
      headerShow: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handelScroll() {
      const top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      if (top > 50) {
        let opacity = top / 120
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.headerShow = false
      } else {
        this.headerShow = true
      }
    }
  },
  created() {
    window.addEventListener('scroll', this.handelScroll)
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.handelScroll)
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/mixin.styl'
@import '~styles/varibles.styl'
    .header-abs
      width .72rem
      line-height .72rem
      background rgba(0, 0, 0, .7)
      border-radius .36rem
      position absolute
      top .2rem
      left .2rem
      color #fff
      text-align center
    .header-fixed
      height 0.88rem
      line-height 0.88rem
      color #ffffff
      background $bgColor
      position fixed
      z-index 3
      top 0
      left 0
      right 0
      bottom 0
      .header-tit
        font-size .32rem
        margin 0 1rem
        text-align center
        ellipsis()
      .header-left
        color #fff
        position absolute
        top 0
        left 0
        .back-icon
          text-align center
          font-size 0.36rem
          width .8rem
</style>
